﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Landscape.Business.FNH.Activities;
using Landscape.Business.FNH;

namespace Landscape.WebApp.Controls
{
    public partial class StatusItemHistory : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ICode"] != null && Request.QueryString["SICode"] != null)
            {
                Guid incCode = Guid.Parse(Request.QueryString["ICode"]);
                Guid statusItemCode = Guid.Parse(Request.QueryString["SICode"]);

                using (var nhSession = NHSessionManager.GetManager().GetSession())
                {
                    EmergencyActivities emActs = new EmergencyActivities(nhSession);
                    this.rgHistory.DataSource = emActs.GetIncidentByCode(incCode).StatusBoardLog.Where(exp => exp.StatusItem.ID == statusItemCode).OrderBy(exp=>exp.CreatedDate).ToList();
                    this.rgHistory.DataBind();
                }
            }
        }

        protected void rgHistory_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item.ItemType == Telerik.Web.UI.GridItemType.Item || e.Item.ItemType == Telerik.Web.UI.GridItemType.AlternatingItem)
            {
                var userCode = Guid.Parse(e.Item.Cells[4].Text);
                AdminActivities adminActs = new AdminActivities();
                var uObject = adminActs.GetUserMasterByID(userCode);

                e.Item.Cells[4].Text = uObject.FirstName + " " + uObject.LastName;
            }
        }
    }
}